package functions.ems_process_service;

import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.crc.mam.BaseCase;

import coms.AutoException;
import coms.Constants;
import coms.process.LoginTest;
import frame.FrameWork;
import frame.HttpHelper;
import frame.InterTest;


public class FindImportFailList extends BaseCase implements InterTest{

	private static Logger logger = LoggerFactory.getLogger(FindImportFailList.class);
	private String claimNo;	
	@Override
	public void run(Map<Object, Object> paramMap) {
		logger.info("登录-------");
		String baseUrl = (String)paramMap.get("baseUrl");
		if (baseUrl != null) {
			FrameWork.setBaseUrl(baseUrl);
		}
		LoginTest loginTest = new LoginTest();
		loginTest.run(paramMap);
		if (!loginTest.status) {
			this.remark = loginTest.result;
			this.status = false;
			throw new AutoException("登录失败: " + this.remark + "，阻碍测试");
		}
		logger.info("根据单号"+claimNo+"查询----------start-----");
		
		String url = Constants.FIND_IMPORT_FAIL_LIST;
		String param="{\"page\":{\"currentPage\":1,\"pageSize\":10,\"recordCount\":46},"
				+ "\"params\":{\"claimNo\":\"\",\"invoiceBatchNo\":\"\",\"ouCode\":\"\",\"groupCode\":\"\",\"glDate\":\"\","
				+ "\"queryDateStart\":\"\",\"queryDateEnd\":\"\",\"importFlag\":\"\",\"approveEndEmpName\":\"\"},"
				+ "\"sortDTO\":{\"fieldName\":\"\",\"orderBy\":\"\"}}";
		try {
			this.result=HttpHelper.post(param, url);
			logger.info("查找的结果------"+result);
			JSONObject jsonObject =  new JSONObject(result);
			int failNum=jsonObject.getInt("total");
			logger.info("待导入的发票共有"+failNum);
			if (this.status) {
				JSONArray jsonArray = jsonObject.getJSONArray("list");
				setStatus(true);
				this.remark="total:"+failNum;
			}
			
			System.out.println(status);
			System.out.println(remark);
		} catch (Exception e) {
			e.printStackTrace();
			this.status = false;
			this.remark = "系统异常";
		}				
		logger.info("待导入发票查询--------end---------");				
	}

	@Override
	public boolean getStatus() {
		// TODO Auto-generated method stub
		return false;
	}

}
